#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
using namespace std;
struct node{
    int d,v,a;
}h[100003];
int p[100003];
int vis[100003];
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        memset(vis,0,sizeof(vis));
        int n,m,l,vv,ans=0;
        cin>>n>>m>>l>>vv;
        for(int i=1;i<=n;i++) cin>>h[i].d>>h[i].v>>h[i].a;
        for(int i=1;i<=m;i++) cin>>p[i];
        for(int i=1;i<=n;i++){
            int j=1;
            for(;j<=m;j++)
                if(h[i].d<=p[j]){
                    //cout<<h[i].d<<' '<<p[j]<<'\n';
                    break;
                }
            if(h[i].v>vv){
                ans++;
                for(int jj=j;jj<=m;jj++) vis[jj]=1;
            }
        }
        cout<<ans<<' ';
        int ans2=0;
        for(int i=1;i<=m;i++)
            if(vis[i]==0) ans2++;
        cout<<ans2<<'\n';
    }
    return 0;
}/*1
5 5 15 3
1 2 0
2 1 0
6 4 0
12 3 0
14 2 0
2 5 8 9 15*/
